package com.kye.express.business.welfare_integral_strategy;

import android.content.Context;
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.webkit.WebView;

import com.kye.express.R;
import com.kye.express.business.base.BaseToolbarActivity;
import com.kye.express.databinding.ActivityIntegralStrategyBinding;
import com.kye.webview.WebViewFragment;

public class IntegralStrategyActivity extends BaseToolbarActivity implements IntegralStrategyContract.IntegralStrategyView {

    private ActivityIntegralStrategyBinding mBinding;
    private WebViewFragment mWebViewFragment;
    private WebView mWebView;
    private IntegralStrategyContract.IntegralStrategyPresenter mPresenter;

    public static void startActivity(Context context) {
        context.startActivity(
                new Intent(context, IntegralStrategyActivity.class)
        );
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initViews();
        initEvents();
        initData();
    }

    private void initViews() {
        mBinding = DataBindingUtil.setContentView(this, R.layout.activity_integral_strategy);
        setUpToolbar(mBinding.toolbar);
        mBinding.toolbar.setTitleTextColor(getResources().getColor(R.color.white));
        mPresenter = new IntegralStrategyContract.IntegralStrategyPresenter();
        mWebViewFragment = WebViewFragment.newInstance("https://res.ky-express.com/activity/integral/integral.html", true);
    }

    private void initEvents() {
//        RxView.clicks(mBinding.llErrorNet.btErrorNetRetry)
//                .compose(new DebounceObservableTransformer<>())
//                .subscribe(new Consumer<Object>() {
//                    @Override
//                    public void accept(Object o) throws Exception {
//                        mWebView.loadUrl("https://res.ky-express.com/activity/integral/integral.html");
//                        mBinding.statusLayout.showContentView();
//                    }
//                });
        mWebViewFragment.setShowProgress(true);
        mWebViewFragment.setWebViewCallback(new WebViewFragment.WebViewCallback() {
            @Override
            public void callBack(WebView webView) {
                mWebView = webView;
            }
        });
//        mWebViewFragment.setOnReceiveErrorListener(new WebViewFragment.OnReceiveErrorListener() {
//            @Override
//            public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
//                mBinding.statusLayout.showErrorNetworkView();
//            }
//        });
    }

    private void initData() {
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.frame_layout_container, mWebViewFragment).commit();
        mPresenter.bind(this);
//        mBinding.statusLayout.showContentView();
    }

}
